package com.gxa.modules.communityManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Query;
import com.gxa.modules.communityManagement.entity.HouseholdManagement;
import com.gxa.modules.communityManagement.mapper.HouseholdManagementMapper;
import com.gxa.modules.communityManagement.service.HouseholdManagementService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class HouseholdManagementServiceImpl extends ServiceImpl<HouseholdManagementMapper, HouseholdManagement> implements HouseholdManagementService {

    @Override
    public PageUtils queryByPage(Map<String, Object> params) {
        String type = (String)params.get("type");
        String name = (String)params.get("name");
        String serialNo = (String)params.get("serialNo");
        String communityId = (String)params.get("communityId");
        String phoneNumber = (String)params.get("phoneNumber");
        String ptime = (String)params.get("ptime");
        String startTime =(String)params.get("startTime");
        String stopTime=(String)params.get("stopTime");

        if(startTime !=null && startTime!=""){
            IPage<HouseholdManagement> page = this.page(new Query<HouseholdManagement>().getPage(params),
                    new QueryWrapper<HouseholdManagement>().like(StringUtils.isNotEmpty(type),"type",type)
                            .eq(StringUtils.isNotEmpty(name),"name",name)
                            .eq(StringUtils.isNotEmpty(communityId),"community_id",communityId)
                            .eq(StringUtils.isNotEmpty(phoneNumber),"phone_number",phoneNumber)
                            .eq(StringUtils.isNotEmpty(serialNo),"serial_no",serialNo)
                            .between("ptime",startTime,stopTime)
                            .eq(StringUtils.isNotEmpty(ptime),"ptime",ptime)
            );
            return new PageUtils(page);
        }else {
            IPage<HouseholdManagement> page1 = this.page(new Query<HouseholdManagement>().getPage(params),
                    new QueryWrapper<HouseholdManagement>().like(StringUtils.isNotEmpty(type),"type",type)
                            .eq(StringUtils.isNotEmpty(name),"name",name)
                            .eq(StringUtils.isNotEmpty(communityId),"community_id",communityId)
                            .eq(StringUtils.isNotEmpty(phoneNumber),"phone_number",phoneNumber)
                            .eq(StringUtils.isNotEmpty(serialNo),"serial_no",serialNo)
                            .eq(StringUtils.isNotEmpty(ptime),"ptime",ptime)
            );
            return new PageUtils(page1);
        }

    }

    @Override
    public PageUtils queryByPage1(Map<String, Object> params) {
        String phoneNumber = (String)params.get("phoneNumber");
        IPage<HouseholdManagement> page = this.page(new Query<HouseholdManagement>().getPage(params),
                new QueryWrapper<HouseholdManagement>().like(StringUtils.isNotEmpty(phoneNumber),"phone_number",phoneNumber)
        );
        return new PageUtils(page);
    }

}
